<template>
  <div class="luotong">
    <div v-if="!inline" class="content_title" style="cursor: pointer" @click="showDialogTech">
      <span class="content_text">络筒</span>
      <img class="content_img" src="@/assets/img/chart/luotong.png" alt="" srcset="" />
    </div>
    <div class="luotong_body">
      <div class="luotong_row2">
        <div
          class="item"
          v-if="$store.state.workshopNo == 2"
          v-for="(item, index) in luoTongData.luotongRow1Data"
          :key="index + '1'"
        >
          <div v-if="index == 4 || index == 8">
            <div :class="{ dongli_inline: inline, dongli: !inline }" @click="clickHandleDl('luotong2_' + index)">
              <img src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div v-if="Number(item.deviceNo) % 2 == 0" @click="clickHandle(item)">
            <luotong_l :data="item"></luotong_l>
          </div>
          <div v-if="Number(item.deviceNo) % 2 != 0" @click="clickHandle(item)">
            <luotong_r :data="item"></luotong_r>
          </div>
          <div v-if="index == 6">
            <div :class="{ wendu_inline: inline, wendu: !inline }">
              <img src="@/assets/img/wendu.png" alt="" srcset="" />
            </div>
          </div>
        </div>
        <div
          class="item"
          v-if="$store.state.workshopNo == 3"
          v-for="(item, index) in luoTongData.luotongRow1Data"
          :key="index + '1'"
        >
          <div v-if="index == 4 || index == 7">
            <div :class="{ dongli_inline: inline, dongli: !inline }" @click="clickHandleDl('luotong2_' + index)">
              <img src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div v-if="Number(item.deviceNo) % 2 == 0" @click="clickHandle(item)">
            <luotong_l :data="item"></luotong_l>
          </div>
          <div v-if="Number(item.deviceNo) % 2 != 0" @click="clickHandle(item)">
            <luotong_r :data="item"></luotong_r>
          </div>
          <div v-if="index == 6">
            <div :class="{ wendu_inline: inline, wendu: !inline }">
              <img src="@/assets/img/wendu.png" alt="" srcset="" />
            </div>
          </div>
        </div>
        <div
          class="item"
          v-if="$store.state.workshopNo == 5"
          v-for="(item, index) in luoTongData.luotongRow1Data"
          :key="index + '1'"
        >
          <div v-if="index == 3 || index == 7">
            <div :class="{ dongli_inline: inline, dongli: !inline }" @click="clickHandleDl('luotong2_' + index)">
              <img src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div v-if="Number(item.deviceNo) % 2 == 0" @click="clickHandle(item)">
            <luotong_l :data="item"></luotong_l>
          </div>
          <div v-if="Number(item.deviceNo) % 2 != 0" @click="clickHandle(item)">
            <luotong_r :data="item"></luotong_r>
          </div>
          <div v-if="index == 6">
            <div :class="{ wendu_inline: inline, wendu: !inline }">
              <img src="@/assets/img/wendu.png" alt="" srcset="" />
            </div>
          </div>
        </div>
        <div
          class="item"
          v-if="$store.state.workshopNo == 6"
          v-for="(item, index) in luoTongData.luotongRow1Data"
          :key="index + '1'"
        >
          <div v-if="index == 6 || index == 10">
            <div :class="{ dongli_inline: inline, dongli: !inline }" @click="clickHandleDl('luotong2_' + index)">
              <img src="@/assets/img/dongligui.png" alt="" srcset="" />
            </div>
          </div>
          <div v-if="Number(item.deviceNo) % 2 == 0" @click="clickHandle(item)">
            <luotong_l :data="item"></luotong_l>
          </div>
          <div v-if="Number(item.deviceNo) % 2 != 0" @click="clickHandle(item)">
            <luotong_r :data="item"></luotong_r>
          </div>
          <div v-if="index == 6">
            <div :class="{ wendu_inline: inline, wendu: !inline }">
              <img src="@/assets/img/wendu.png" alt="" srcset="" />
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 络筒弹窗控件 -->
    <luoTongDialog v-if="showModal" :defaultData="data1" ref="luoTongDialog"></luoTongDialog>
    <!-- 动力柜弹窗控件 -->
    <dongliDialog v-if="showDongliModal" ref="dongliDialog" />
    <!-- 络筒工艺详情 -->
    <luotong-dialog-tech v-if="techShow" ref="luotongDialogTech"></luotong-dialog-tech>
  </div>
</template>

<script>
import luoTongDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_luotong/index'
import dongliDialog from '@/views/monitorCenter/workChart/components/qcs/dialog/dialog_dongli/index'
import luotong_l from '@/views/monitorCenter/workChart/components/qcs/luotong_l'
import luotong_r from '@/views/monitorCenter/workChart/components/qcs/luotong_r'
import COMMON from '@/utils/common'
import dongLiMenu from '@/assets/data/dongli.json'
import dongliItem from '@/assets/data/dongliItem.json'
export default {
  name: 'LuoTong',
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: {
    luoTongDialog,
    luotong_l,
    luotong_r,
    dongliDialog
  },
  data() {
    return {
      luoTongData: {
        luotongRow1Data: [],
        luotongRow2Data: []
      },
      dongLiMenu: {},
      dongLiItem: {},
      showModal: false,
      showDongliModal: false,
      techShow: false
    }
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.luotongDialogTech = require('@/views/monitorCenter/workChart/components/qcs/dialogBig/dialog_luotong_tech/index').default
  },
  created() {
    this.dongLiMenu = dongLiMenu
    this.dongLiItem = dongliItem
  },
  computed: {
    luoTongGroupState() {
      let result
      if (this.$store.state.socketData.length != 0) {
        result = this.$store.state.socketData.filter(item => item.workshop == this.$store.state.workshopNo)
        result = result[0].dsDeviceRealTimeStatusListSpooling
      }
      return result
    }
  },
  watch: {
    luoTongGroupState: {
      immediate: true,
      handler(val) {
        if (val) {
          this.luoTongData.luotongRow1Data = val
        }
      }
    }
  },
  methods: {
    closeHandle() {
      this.showModal = false
      this.showDongliModal = false
    },
    clickHandle(item) {
      this.data1 = item
      this.data1.classes = this.$store.state.workshopData.shiftSpoolingTxt
      this.showModal = true
    },
    clickHandleDl(item) {
      this.showDongliModal = true
      var dialogData = this.dongLiItem[`${item}_${this.$store.state.workshopNo}`]
      this.$nextTick(() => {
        this.$refs.dongliDialog.showDialog(dialogData)
      })
    },
    showDialogTech() {
      this.techShow = true
    },
    closeDialogTech() {
      this.techShow = false
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/workshop.less';
.wendu_inline {
  position: absolute;
  transform: translate(400px, -150px);
  img {
    width: 30px;
    height: 30px;
  }
}
.dongli_inline {
  position: absolute;
  transform: translateX(450px);
  img {
    width: 30px;
    height: 15px;
  }
}
</style>
